// Fretta base atempt for the IMiniGame :)

local MiniGame = IMiniGame.New()
local Vars = MiniGame["Vars"]
local Functions = MiniGame["Functions"]
local Hooks = MiniGame["Hooks"]

Vars.TimeToEnd = CurTime() + 5
Vars.EndedTime = CurTime()
Vars.MaxPostGameTime = 5
Vars.IsInGame = false
Vars.RoundTime = 60

function MiniGame:RoundEnd() end

function Functions.RoundEnd()
	Vars.EndedTime = CurTime()
	Vars.TimeToEnd = CurTime() + Vars.MaxPostGameTime
	Vars.IsInGame = false
	
	MiniGame:RoundEnd()
end

function MiniGame:RoundStart() end

function Functions.RoundStart()
	
	Vars.TimeToEnd = 0
	Vars.EndedTime = 0
	Vars.MaxPostGameTime = 5
	Vars.IsInGame = true
	
	timer.Simple( Vars.RoundTime , Functions.RoundEnd )
	
	MiniGame:RoundStart()
	
end


function Functions.PostGameThink()
	if ( Vars.TimeToEnd == Vars.EndedTime + Vars.MaxPostGameTime ) then
		return true -- Start New Game
	else
		return false -- Continue waiting
	end
end

function Functions.OnPostLoad()
	Functions.RoundStart()
end

function Functions.OnUnload()
	Functions.RoundEnd()
	return true
end

function Hooks.Think()
	if ( Vars.IsInGame == false ) then
		local should = Functions.PostGameThink()
		if ( should ) then
			Functions.RoundStart()
		end
	end
end

MiniGame:RegisterBase( "Fretta" )